/*
 * MagmonDataSetGuidance.java
 *
 * Created on September 11, 2002, 3:04 PM
 *
 * Copyright (c) 2002 The General Electric Company
 */

package com.ge.healthcare.autosc.processor.shemjob.guidance.dataset;

import com.ge.healthcare.autosc.common.exceptions.BasicException;

/**
 * Guidance information for magnet monitor data sets.
 *
 * @author Daniel S. Horwitz, Compuware Corp.
 *
 * @version AutoSC P5P6
 */
public class MagmonDataSet
{
    /**
     * Identifier for the currently defined functions.  When a new function
     *  is added, it must be added to this list.
     */
    /** CopySameNameDataFunc XML tag.  */
    public static final int COPY_SAME_NAME_DATA_FUNC = 0;
    /** IgnoreDataFunc XML tag.  */
    public static final int IGNORE_DATA_FUNC = 1;
    /** CopyDataMoveOldFunc XML tag.  */
    public static final int COPY_DATA_MOVE_OLD_FUNC = 2;
    /** CopySortFunc XML tag.  */
    public static final int COPY_SORTED_FUNC = 3;
    /** IntegrateDataFunc XML tag.  */
    public static final int INTEGRATE_DATA_FUNC = 4;

    /**
     * Table for converting data set function name to data set function
     *  identifier.  When a new function is added, it must be added to
     *  this list.
     */
    private static final String[] functionNameList = new String[] {
        "CopySameNameDataFunc",    // COPY_SAME_NAME_DATA_FUNC
        "IgnoreDataFunc",          // IGNORE_DATA_FUNC
        "CopyDataMoveOldFunc",     // COPY_DATA_MOVE_OLD_FUNC
        "CopySortedFunc",          // COPY_SORTED_FUNC
        "IntegrateDataFunc"        // INTEGRATE_DATA_FUNC
    };

    /**
     * Identifier of the data set function to perform.
     */
    private int theFunction = 0;

    /**
     * List of arguments for the function.
     */
    private String[] theArgList = null;

    /**
     * Create a magnet monitor data set guidance instance.
     *
     * @param functionName The name of the data set function to perform.
     *
     * @param argList The list of arguments for the function.
     *
     * @exception Exception If the function name is not one of the
     *  recognized names or the number of arguments in the argument
     *  list is incorrect for the specified function.
     */
    public MagmonDataSet( String functionName, String[] argList )
        throws BasicException {
        theFunction = getIdentifierFor( functionName );
        /*
         * Do not see the need to check this when xsd is able to enforce the same.
         * Update the xsd to make sure all arguments is required
        final int expectedNumArgs = numArgsList[theFunction];
        if ( argList.length != expectedNumArgs )
        {
            String message = "Unexpected number of arguments for " +
                             functionName +
                             ".  Expected: " +
                             expectedNumArgs +
                             "  Actual: " +
                             argList.length;
            throw new Exception( message );
        } */
        theArgList = argList;
    }

    /**
     * Get the event function identifier for the specified event function
     *  name.
     *
     * @param functionName The name of the data set function to perform.
     *
     * @return The event function identifier for the function name.
     *
     * @exception Exception If the data set function name is not one of
     *  the recognized names.
     */
    private int getIdentifierFor( String functionName ) throws BasicException
    {
        for ( int idx = 0; idx < functionNameList.length; idx += 1 )
        {
            if ( functionName.equals( functionNameList[idx] ) )
            {
                return idx;
            }
        }
        String message =
            functionName + " is not a valid DataSetGuidance function type";
        throw new BasicException( message );
    }

    /**
     * Get the identifier of the data set function to perform.
     *
     * @return The identifier of the data set function to perform.
     */
    public int getFunction()
    {
        return theFunction;
    }

    public String getFunctionName() {
    	return functionNameList[theFunction];
    }
    
    /**
     * Get the arguments for the function.
     *
     * @return The arguments for the function.
     */
    public String[] getArgList()
    {
        return theArgList;
    }

    /**
     * Return a string representation of the object.
     *
     * @return A string representation of the object.
     */
    public String toString()
    {
        StringBuffer buffer = new StringBuffer();
        buffer.append( theFunction );
        buffer.append( ':' );
        buffer.append( functionNameList[theFunction] );
        buffer.append( '(' );
        for ( int idx = 0; idx < theArgList.length; idx += 1 )
        {
            if ( idx != 0 )
            {
                buffer.append( ',' );
            }
            buffer.append( theArgList[idx] );
        }
        buffer.append( ')' );
        return buffer.toString();
    }
}
